QUERY_VIDEO

QUERY_VIDEO obtains information about a video file without having to open and read it.

Note: Frame counts may vary slightly depending on the method used to obtain the count. Variabilities in timestamps and video standards, discontinuities in the videos themselves, or differences in the types of frames may influence the apparent frame count.

Note: Animated GIF files do not contain header information on the frame rate, duration, or the number of frames. These values are estimated from other header information and may be incorrect.

Note: QUERY_VIDEO is not available with the IDL Virtual Machine.

Examples

Example 1 - Obtain Information About a Video File

The following example uses a NASA video displaying the Coronal Mass Ejection (CME) event of August, 2012. The video is available online (see Resources and References, below) or in the \examples\data directory of your IDL installation.

Copy the following to the IDL command line to obtain information about the CME.mp4 file:

; Define the file to query.

file = FILEPATH('CME.mp4', $

   SUBDIRECTORY=['examples','data'])

 

myVideoQuery = QUERY_VIDEO(file, info, STREAMS=vidStreams)

PRINT, info

HELP, info

 

IDL returns:

 

From this we can tell that the dimensions are 512x288, it's a video with 574 frames, is 19.1525 seconds long, written in the H.264/MPEG-4 codec, and has 29.97 frames per second playback rate. Now check the content of the vidStreams variable:

 

HELP, vidStreams

 

IDL displays similar information stored in the vidStreams variable:

 

Example 2: Get Codec and Format Information

Copy the following lines of code to the IDL command line to obtain general information about the codecs and formats currently supported in IDL:

 

result = QUERY_VIDEO(CODECS_READ=cRead, CODECS_WRITE=cWrite, $

   FORMATS_READ=fRead, FORMATS_WRITE=fWrite)

 

PRINT, cRead

PRINT, cWrite

PRINT, fRead

PRINT, fWrite

 

IDL displays all of the current codec and format information.

Syntax

Result = QUERY_VIDEO( Filename [, Info] [, /AUDIO] [, CODECS_READ=variable] [, CODECS_WRITE=variable] [, FORMATS_READ=variable] [, FORMATS_WRITE=variable] [, METADATA=variable] [, STREAMS=variable] [, /VIDEO])

Return Value

This routine returns a long with the value of 1 (one) if the query was successful and the file type was correct, or 0 (zero) on failure, along with other information about the file.

Arguments

Filename

Set Filename to a scalar string containing the full path to a video file to query.

Note: This argument is not required when retrieving information on codecs or formats.

Info

Returns an anonymous structure containing information about the file.

Field

IDL Data Type

IDL Data Type

Dimensions

2-D long array

[width, height] of the first video stream in the file.

Type

String

String identifying the file format: "VIDEO".

Num_Frames

Long

The number of frames in the first video stream.

Length

Float

The length, in seconds, of the first video stream.

Codec

String

The codec used to encode the first video stream.

Rate

Float

The desired playback rate of the first video stream.

Keywords

AUDIO

Set this keyword in conjunction with CODECS_READ or CODECS_WRITE to return the audio codecs. The default is to return both video and audio codecs.

CODECS_READ

Assign CODECS_READ to a named variable in which to return a string array listing all the readable codecs currently supported.

CODECS_WRITE

Set this keyword to a named variable in which to return a string array listing all the writable codecs currently supported.

FORMATS_READ

Set this keyword to a named variable in which to return a string array listing all the readable formats currently supported.

FORMATS_WRITE

Assign FORMATS_WRITE to a named variable in which to return a string array listing all the writable formats currently supported.

METADATA

Set this keyword to a named variable in which to return a 2-dimensional string array containing all of the metadata in the file. Each pair of strings will represent a [key, value] pair of metadata.

STREAMS

Assign STREAMS to a named variable to return an array of structures describing the streams available in the currently open file. If no streams are found, IDL returns !NULL.

Field

IDL Data Type

IDL Data Type

PID

Long

Internal ID of the stream.

Type

Ulong

0=unknown; 1=video; 2=audio; 3=data.

Rate

Float

For video: frames per second. For audio: Hertz

Width

Ulong

For video: width in pixels of a frame

Height

Ulong

For video: height in pixels of a frame

Channels

Ulong

Number of audio channels in the stream.

Codec

String

Codec used for encoding the stream.

Length

Float

Time, in seconds, of the stream.

Count

Ulong

Number of frames or data packets in the stream.

Note: IDL takes the information returned from the metadata written in the file. It is possible, depending on the file's encoding, for the actual length and count to be different than what is returned here. To obtain the actual number of frames and the time stamp on each frame, use the TIME_OUT and NODATA keywords to READ_VIDEO.

VIDEO

Set this keyword in conjunction with CODECS_READ or CODECS_WRITE to return the video codecs. The default is to return both video and audio codecs.

Version History

8.2.3

Introduced

Resources and References

The NASA "CME.mp4" video used in the example is courtesy of the Solar Dynamics Observatory (SDO) and the Solar and Heliospheric Observatory (SOHO). The file is available for download here:

https://www.nasa.gov/multimedia/videogallery/index.html?media_id=160387251

A longer, similar video that can be substituted in the example code, is available for download here:

https://www.nasa.gov/mission_pages/sdo/news/coronal-rain.html

See Also

Creating Video, IDLffVideoRead, IDLffVideoWrite, READ_VIDEO, WRITE_VIDEO